package 晚间作业0309;

public class Doc07 {

    /**
     * 1. （中）设计一个圆类，具有属性：圆心（点）、半径。添加一个方法：判断一个圆是否包含一个点。
     */
    public static class Doc07_01 {
        public static void main(String[] args) {
            Circle circle = new Circle(new Point(-1, -1), 2);
            System.out.println(circle.isContainsPoint(new Point(3, 3)));
        }

        public static class Point {
            private double x;
            private double y;

            public Point(double x, double y) {
                this.x = x;
                this.y = y;
            }

            public double getDistanceOfPoint(Point p) {
                return Math.sqrt(Math.pow(x - p.x, 2) + Math.pow(y - p.y, 2));
            }
        }

        public static class Circle {
            private Point center;
            private double radius;

            public Circle(Point center, double radius) {
                this.center = center;
                this.radius = radius;
            }

            /**
             * 文档07-1
             * @param p 比较点
             * @return true包含，false不包含
             */
            public boolean isContainsPoint(Point p) {
                return p.getDistanceOfPoint(center) <= radius;
            }
        }
    }

    /**
     * 2. （中）设计一个点类，具有属性：x、y坐标，具有方法：和另外一个点相加，得到一个新的点，新的点的x坐
     * 标是原来两个点的x坐标和，y是原来两个点的y坐标和
     */
    public static class Doc07_02 {
        public static void main(String[] args) {
            System.out.println(new Point(-1, -2).addPoint(new Point(3.0, 4.0)).toString());
        }

        public static class Point {
            private double x;
            private double y;

            public Point(double x, double y) {
                this.x = x;
                this.y = y;
            }

            /**
             * 文档07-2
             * @param p 另外一个点
             * @return 相加后的新点
             */
            public Point addPoint(Point p) {
                return new Point(x + p.x, y + p.y);
            }

            @Override
            public String toString() {
                return "[" + x + ", " + y + ']';
            }
        }
    }

    /**
     * 5. （非常难）小明交换牌：小明左手和右手分别拿了一张扑克牌，需要交换两只手中的扑克牌。最后小明展示
     * 交换后的扑克牌。扑克牌有花色和点数属性。
     */
    public static class Doc07_05 {
        public static void main(String[] args) {
            Gamer xiaoming = new Gamer("小明",
                    new Hand("左手", new Poker("梅花", "三")),
                    new Hand("右手", new Poker("红心", "A")));
            xiaoming.show();
            xiaoming.switchLeftAndRight();
            xiaoming.show();
        }

        public static class Poker {
            //花色
            private String mark;
            //点数
            private String point;

            public Poker(String mark, String point) {
                this.mark = mark;
                this.point = point;
            }

            @Override
            public String toString() {
                return mark + point;
            }
        }
        public static class Hand {
            private String name;
            private Poker poker;

            public Hand(String name, Poker poker) {
                this.name = name;
                this.poker = poker;
            }

            public void setPoker(Poker poker) {
                this.poker = poker;
            }

            public Poker getPoker() {
                return this.poker;
            }
        }
        public static class Gamer {
            private String name;
            private Hand left;
            private Hand right;

            public Gamer(String name, Hand left, Hand right) {
                this.name = name;
                this.left = left;
                this.right = right;
            }

            public void switchLeftAndRight() {
                Poker poker = left.getPoker();
                left.setPoker(right.getPoker());
                right.setPoker(poker);
            }

            public void show() {
                System.out.println("左手：" + left.poker.toString() + "\t" + "右手：" + right.poker.toString());
            }
        }
    }
}
